package com.sinopec.android.adapter;

import java.util.ArrayList;


import com.sinopec.android.R;
import com.sinopec.android.bean.Thing;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
* @ClassName: DocumentManagementListAdapter
* @Description: TODO(公文管理适配器)
* @author liuwei
* @date 2012-3-28 下午04:07:10
* 
*/
public class DocumentManagementListAdapter extends BaseAdapter {
	public ArrayList<Thing> listData;
	private Thing thingBean;
	private Context context;
	private LayoutInflater inflater ;
	
	public DocumentManagementListAdapter(Context context,ArrayList<Thing> listData){
		this.context = context;
		inflater = LayoutInflater.from(context);
		this.listData = listData;
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		if(listData!=null){
			return listData.size();
		}
		return 0;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
		if(convertView ==null){
			viewHolder = new ViewHolder();
			convertView = inflater.inflate(R.layout.document_management_item, null);
			viewHolder.name = (TextView) convertView.findViewById(R.id.thing_name_textview);
			viewHolder.title = (TextView) convertView.findViewById(R.id.thing_title_textview);
			viewHolder.date = (TextView) convertView.findViewById(R.id.thing_date_textview);
			viewHolder.flag = (ImageView) convertView.findViewById(R.id.thing_flag);
			convertView.setTag(viewHolder);
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		if(position % 2 ==0){
			convertView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.odd_item_selector));
		}else{
			convertView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.even_item_selector));
		}
		if(listData!=null){
			thingBean = listData.get(position);
			viewHolder.name.setText(thingBean.getName());
			viewHolder.title.setText(thingBean.getTitle());
			viewHolder.date.setText(thingBean.getDate());
		}
		
		return convertView ;
	}
	
	class ViewHolder{
		TextView name,title,date,url,bussinessID;
		ImageView flag;
		
	}

}
